//
//  DMSyndromeController.m
//  MCNKuaiYi
//
//  Created by ling on 17/1/8.
//  Copyright © 2017年 Mr.Cannon. All rights reserved.
//

#import "DMSyndromeController.h"
#import "DMSyndromeModel.h"
#import "DMSyndromeCell.h"

static NSString *rid = @"cell";

@interface DMSyndromeController ()<UITableViewDataSource>

@property(nonatomic,strong)UITableView *tableView;

@property(nonatomic,strong)NSArray<DMSyndromeModel *> *syndromeList;

@end

@implementation DMSyndromeController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    [self setupUI];
    
    [self loadData];
}


#pragma mark - 数据源方法
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _syndromeList.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    DMSyndromeCell *cell = [tableView dequeueReusableCellWithIdentifier:rid forIndexPath:indexPath];
    
    DMSyndromeModel *model = _syndromeList[indexPath.row];
    
    cell.model = model;
    
    return cell;
}



#pragma mark - 并发症数据加载
- (void)loadData
{
    //http://iosapi.itcast.cn/doctor/complicationList.json.php
    //请求参数:{"page":1,"page_size":15,"ci1_id":1,"ci2_id":3}
    
    NSString *url = @"http://iosapi.itcast.cn/doctor/complicationList.json.php";
    NSDictionary *parameters = @{@"page":@1,@"page_size":@15,@"ci1_id":@1,@"ci2_id":@3};
    
    [DMSyndromeModel getSyndromeDataWithURLString:url andParameters:parameters andSuccessBlock:^(NSArray *newsList) {
        
        _syndromeList = newsList;
        
        dispatch_async(dispatch_get_main_queue(), ^{
           
            [_tableView reloadData];
            
        });
        
    }];
    
}


#pragma mark - 搭建界面
- (void)setupUI
{
    _tableView = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
    
    [_tableView registerClass:[DMSyndromeCell class] forCellReuseIdentifier:rid];
    
    _tableView.rowHeight = 60;
    
    _tableView.dataSource = self;
    
    [self.view addSubview:_tableView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
